package com.kky.pp.activity.settings

import android.os.Bundle
import com.kky.pp.common.Constant
import com.kky.pp.R
import com.kky.pp.entity.AgreementEntity
import com.kky.pp.activity.account.AccountActivity
import com.custom.base.entity.OkHttpBodyEntity
import com.custom.base.http.OkHttpFromBoy
import com.custom.base.http.OkHttpManager
import com.custom.base.http.SDOkHttpResoutCallBack
import com.custom.base.util.IntentUtil
import com.kky.pp.base.TitleBasePresenterImpl
import io.rong.imkit.activity.RongWebviewActivity

class SettingPresenter : TitleBasePresenterImpl<SettingContact.View>() {

    override fun initBundle(bundle: Bundle) {
        mView?.apply {
            containerMyAccount.setOnClickListener {
                IntentUtil.startActivity(AccountActivity::class.java)
            }


            OkHttpManager.instance.requestInterface(object : OkHttpFromBoy {
                override fun addBody(requestBody: OkHttpBodyEntity) {
                    requestBody.setPost(Constant.user_config_url)
                    requestBody.add("code", 2)
                }
            }, object : SDOkHttpResoutCallBack<AgreementEntity>() {
                override fun onSuccess(entity: AgreementEntity) {
                    containerPrivacyPolicy.setOnClickListener {
                        val b = Bundle()
                        b.putString("url", entity.data.privacyPolicy)
                        b.putString("title", mActivity.resources.getString(R.string.privacy_policy))
                        startActivity(RongWebviewActivity::class.java, b)
                    }
                    containerSecurity.setOnClickListener {
                        val b = Bundle()
                        b.putString("url", "www.baidu.com")
                        b.putString("title", mActivity.resources.getString(R.string.security))
                        startActivity(RongWebviewActivity::class.java, b)
                    }

                    containerTerms.setOnClickListener {
                        val b = Bundle()
                        b.putString("url", entity.data.terms)
                        b.putString("title", mActivity.resources.getString(R.string.terms))
                        startActivity(RongWebviewActivity::class.java, b)

                    }
                }
            })
        }
        super<TitleBasePresenterImpl>.initBundle(bundle)
    }

    override fun onBackClick() {
        mActivity.finish()
    }
}